﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ConsoleApplication1;
namespace TestProject2
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void ClearTest()
        {
            string ANSWER = DS_CSV_server.Clear();
            Assert.AreEqual("success", ANSWER);
        }

        [TestMethod]
        public void CreateTest()
        {
            string _newPerson = "person1;person1;23\n";
            string ANSWER = DS_CSV_server.Create(_newPerson);
            Assert.AreEqual("success", ANSWER);
        }

        [TestMethod]// uses 'Clear' and 'Create'
        public void ReadTest()
        {
            DS_CSV_server.Clear();
            string _newPerson = "person1;person1;23\n";
            DS_CSV_server.Create(_newPerson);
            string _newPerson2 = "person2;person2;24\n";
            DS_CSV_server.Create(_newPerson2);
            Assert.AreEqual("0;person1;person1;23\n1;person2;person2;24\n", DS_CSV_server.Read());
        }

        [TestMethod]// uses 'Clear' and 'Create' and 'Read'
        public void DeleteTest()
        {
            DS_CSV_server.Clear();
            string _newPerson = "person1;person1;23\n";
            DS_CSV_server.Create(_newPerson);
            string _newPerson2 = "person2;person2;24\n";
            DS_CSV_server.Create(_newPerson2);
            DS_CSV_server.Delete(0);
            Assert.AreEqual("1;person2;person2;24\n", DS_CSV_server.Read());
        }

        [TestMethod]// uses 'Clear' and 'Create' and 'Read'
        public void UpdateTest()
        {
            DS_CSV_server.Clear();
            string _newPerson = "new1;new2;23\n";
            DS_CSV_server.Create(_newPerson);
            
            int id = 0;
            string ANSWER;
            ANSWER = DS_CSV_server.Update(id, "update1;update2;22\n");
            Assert.AreEqual("success", ANSWER);
            
            string expected = "0;update1;update2;22\n";
            Assert.AreEqual(expected, DS_CSV_server.Read());
        }
    }
}
